package com.sl.au.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.sl.au.entity.PartsWarn;
import com.sl.au.repository.PartsWarnRepository;
import com.sl.au.service.PartsWarnService;



@Service("PartsWarnService")
@Transactional
public class PartsWarnServiceImpl extends BaseServiceImpl implements PartsWarnService {
	@Autowired
	PartsWarnRepository partsWarnRepository;

	@Override
	public PartsWarnRepository getRepository() {
		// TODO Auto-generated method stub
		return this.partsWarnRepository;
	}

	@Override
	public List<PartsWarn> getPartsWarn(int start, int length, String key, String orderName, String dir) {
		Page<PartsWarn> pages = null;
		Pageable pageable = new PageRequest(start / length, length, Sort.Direction.DESC, "itemOrder");
		if (StringUtils.hasText(key)) {
			String id = "";
			pages = partsWarnRepository.findPartsWarn(id,key, pageable);
		} else {
			pages = partsWarnRepository.findAll(pageable);
		}
		return pages.getContent();
	}

//	@Override
//	public List<PartsWarn> getPage(int start, int length, String key, String orderName, String dir) {
//		Page<PartsWarn> pages=null;
//		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"createTime");
//		pages = partsWarnRepository.findAll(pageable);
//		return pages.getContent();
//	}

	@Override
	public List<PartsWarn> getPage(int start, int length, String id ,String key) {
		Page<PartsWarn> pages = null;
		Pageable pageable = new PageRequest(start/length, length, Sort.Direction.DESC, "createTime");
		pages = partsWarnRepository.findPartsWarn(id,key, pageable);
		return pages.getContent();
	}

	@Override
	public Long getCount(String id ,String key) {
		return partsWarnRepository.getPartsWarnCount(id,key);
	}

	@Override
	public List<PartsWarn> getAllWarnById(String id) {
		List<PartsWarn> pages = null;
		pages = partsWarnRepository.findAllWarnById(id);
		return pages;
	}
}
